package com.tjc.timingwheel;

 class TimerTaskEntry implements Comparable<TimerTaskEntry> {

    protected TimerTask timerTask;
    private Long expirationMs;

    protected volatile TimerTaskList list;
    protected TimerTaskEntry next;
    protected TimerTaskEntry prev;


    public TimerTaskEntry(TimerTask timerTask, Long expirationMs) {
        this.timerTask = timerTask;
        this.expirationMs = expirationMs;
        //�����timerTask�������еļ�ʱ��������Ŀ������
        // ��setTimerTaskEntry��ɾ������
        if (timerTask != null) {
            timerTask.setTimerTaskEntry(this);
        }
    }

    public Boolean cancelled() {
        return timerTask.getTimerTaskEntry() != this;
    }

    public void remove() {
        TimerTaskList currentList = this.list;
        // �������һ���߳̽���Ŀ��һ��������Ŀ�б��ƶ�����һ��������Ŀ�б�ʱ����remove��
        // ������list��ֵ�������ģ��ò��������޷�ɾ������Ŀ����ˣ����ԣ�ֱ���б��Ϊ�ա�
        // �ڼ���������£����̻߳ῴ��null���˳�ѭ��������һ���߳��Ժ�Ὣ��Ŀ������һ���б�
        while (currentList != null) {
            currentList.remove(this);
            currentList = list;
        }
    }


    @Override
    public int compareTo(TimerTaskEntry that) {
        return Long.compare(expirationMs, that.expirationMs);
    }

    public TimerTask getTimerTask() {
        return timerTask;
    }

    public void setTimerTask(TimerTask timerTask) {
        this.timerTask = timerTask;
    }

    public Long getExpirationMs() {
        return expirationMs;
    }

}
